package com.baidu.service.impl;

import com.baidu.dao.AdministratorMapper;
import com.baidu.pojo.User;
import com.baidu.service.AdministratorService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdministratorServiceImpl implements AdministratorService {
    @Autowired
    private AdministratorMapper administratorMapper;

    public List<User> test() {
        return administratorMapper.test();
    }

    //管理员登录
    public User login(User user){
        return administratorMapper.login(user);
    }

    //添加用户
    public void addUser(User user){
      administratorMapper.addUser(user);
    }

    //根据id修改用户信息
    public void updateUserById(User user){
        administratorMapper.updateUserById(user);
    }



    //根据id删除用户信息
    public void deleteUserById(Integer uid){
        administratorMapper.deleteUserById(uid);
    }

    //查询所有用户信息
    public List<User> getAllUser(){
        return administratorMapper.getAllUser();
    }

    //分页查询所有用户信息,以及关联的角色信息 第一个参数表示起始位置，第二个参数表示页面容量
    public List<User> getByPage(Integer currentPage,Integer pageSize){
        //计算起始位置
        int start=(currentPage-1)*pageSize;

        //执行分页查询
        List<User> list=administratorMapper.getByPage(start,pageSize);

        return list;
    }

    //分页查询总记录数
    public int count(){
        return administratorMapper.count();
    }

    //根据id查询指定的用户信息
    public  User getUserById(Integer uid){
        return administratorMapper.getUserById(uid);
    }

    //根据用户名查询指定的用户信息
    public User getUserByName(String uname){return administratorMapper.getUserByName(uname);}

    //根据用户名查询指定的用户信息
    public boolean myCheck(String uname){
        User user=administratorMapper.getUserByName(uname);
        if (user!=null){//用户名存在
            return true;
        }else {//用户名不存在
            return false;
        }
    }
}
